import { LoginAction, LoginInitState } from '@/types/store'
import { getToken } from '@/utils/storage'

const initState: LoginInitState = getToken() || {
  token: '',
  refresh_token: '',
}

export default function login(prevState = initState, action: LoginAction) {
  switch (action.type) {
    case 'login/getToken':
      return action.payload
    case 'login/logout':
      return {
        token: '',
        refresh_token: '',
      }
    default:
      return prevState
  }
}
